/*
 * @Description: 全线跟踪根据SVGID修改颜色
 * @Version: 1.0
 * @Date: 2023-07-28 14:18:37
 * @LastEditTime: 2024-03-20 13:42:25
 */


/**
 * 
 * @param tiNo 
 * @param pathNo SVG线段ID
 */
export const refreshSVG = (tiNo: number, pathNo: string) => {
    const element = document.getElementById(pathNo);
    if (element != null){
        const name = element.tagName;
        if (name === 'g'){
            const paths = element.querySelectorAll('path');
            const color = (ColourStrategy as any)[(tiNo)]();
            let strokeWidth;
            if(pathNo.indexOf('CAL2150') !== -1 || pathNo.indexOf('CAL1630') !== -1){
                strokeWidth = '30px';
            }else{
                strokeWidth = '0.04vw';
            }
            paths.forEach((path: SVGPathElement) => {
                path.style.stroke = color;
                path.style.strokeWidth = strokeWidth;
            });
        }else {
            element.style.stroke = (ColourStrategy as any)[(tiNo)]();
            if(pathNo.indexOf('CAL2150') !== -1 || pathNo.indexOf('CAL1630') !== -1){
                element.style.strokeWidth = '30px'
            }else if (pathNo.indexOf('spm')!== -1){
                element.style.strokeWidth = '2px'
            }else if(pathNo.indexOf('combinedCAGalvTempModels')!== -1){
                element.style.strokeWidth = '2px'
            }else{
                element.style.strokeWidth = '0.03vw'
            }
        }
    }
}

export const initialSVG = (technologicalName: string,name: string,channelNo:string) => {
    // 安全检查：确保 channelNo 是 '1' 或 '2'，并且 DisplayStrategy[channelNo] 是函数
    if (channelNo !== '1' && channelNo !== '2') {
        return;
    }
    
    const strategyFunc = (DisplayStrategy as any)[channelNo];
    if (typeof strategyFunc !== 'function') {
        return;
    }
    
    const strategyValue = strategyFunc();
    refreshGraphical(-1,`${technologicalName}-ZONE_${name}${strategyValue}`)
    refreshSVG(-2,`${technologicalName}-ZONE_${name}${strategyValue}_path`)
}
export const refreshGraphical = (tiNo:number,key:string)=>{
    const element = document.getElementById(key);
    if (element != null) {
        element.style.stroke = (ColourStrategy as any)[(-2)]();
        element.style.fill = (ColourStrategy as any)[(tiNo)]();
    }
}


export enum ColourType {
    ZERO = 0,
    ONE = 1,
    TWO = 2,
    THREE = 3,
    FOUR = 4,
    FIVE = 5,
    SEX = 6,
    SEVEN = 7,
    EIGHT = 8,
    NINE = 9,
    INITLINE = -1,
    INITLGRAPHICAL = -2,

}
const ColourStrategy = {
    [ColourType.ZERO]: () => ("#FF6600"),
    [ColourType.ONE]: () => ("#FF00FF"),
    [ColourType.TWO]: () => ("#CC3300"),
    [ColourType.THREE]: () => ("#0099FF"),
    [ColourType.FOUR]: () => ("#F08080"),
    [ColourType.FIVE]: () => ("#C0C0C0"),
    [ColourType.SEX]: () => ("rgba(255,128,64,255)"),
    [ColourType.SEVEN]: () => ("#C71585"),
    [ColourType.EIGHT]: () => ("rgba(147,147,0,255)"),
    [ColourType.NINE]: () => ("rgba(255,128,192,255)"),
    [ColourType.INITLINE]: () => ("#5F6368"),
    [ColourType.INITLGRAPHICAL]: () => ("#1E1E1E"),
}

export enum ThoroughfareType {
    ONE = '1',
    TOW = '2',
}
const DisplayStrategy: Record<string, () => number> = {
    '1': () => (2),
    '2': () => (1),
}